<?php
class Sb_Dispatcher
{
    private static function initAutoLoad()
    {

        function __autoload($className)
        {
            
            $classNameArr = explode('_', $className);
            $pathToClass = '';
            $ds = DIRECTORY_SEPARATOR;

            foreach($classNameArr as $partOfPath){
                if($pathToClass){
                    $pathToClass .= $ds;
                }
                $pathToClass .= $partOfPath;
            }

            $pathToClass .= '.php';
            require_once $pathToClass;
        }
    }

    public static function run()
    {
        self::initAutoLoad();
        $http = Sb_Http::getInstance();
        $className = 'Sb_Ctrl_'.$http->getModuleName().'_'.$http->getControllerName();
        //var_dump($className);die;
        try{
            $ctrl = new $className();
            $ctrl->dispatch($http->getActionName().'Action');
        }catch(Exception $e){
            var_dump($e->getMessage());
        }
    }
}